<?php
$fn_strona = "./strona.html";
$fn_users = "./users.txt";

if(!isSet($_GET["user"]) || !isSet($_GET["pass"])){
  die("error\nNieprawidowe wywoanie skryptu.");
}

if(!$fp = @fopen($fn_users, "r")){
  die("error\nBd sewera. Zalogowanie nie jest moliwe.");
}

$user = $_GET["user"];
$pass = $_GET["pass"];

$found = false;
while (!feof($fp)){
  $str = rtrim(fgets($fp));
  $arr = explode(":", $str);
  if(count($arr) != 2)
    continue;
  if($arr[0] == $user){
    if(sha1($arr[1]) == $pass){
      $found = true;
      break;
    }
    else{
      break;
    }
  }
}

if($found){
  if(is_readable($fn_strona)){
    @readfile($fn_strona);
  }
  else{
    die("error\nStrona nie jest w tej chwili dostpna.");
  }
}
else{
  echo "error\nPodane dane s nieprawidowe.";
}
?>